ListFBetaScore metric
Bases: FBetaScore
F-beta on label sets; use for (multi-)label tasks, not free text.
Formula:
This is the weighted harmonic mean of precision and recall.
Its output range is [0, 1]. It operates at a label level
and can be used for classification or retrieval pipelines.
The difference between this metric and F1Score is that this one considers
each element of the list (or the string value) as one label, comparing
label sets rather than tokenized words.
If labels is provided, accumulation is performed per-label (sklearn-style):
for each label L, tp[L] += 1 when L appears in both y_true and
y_pred, fp[L] += 1 when it appears only in y_pred, fn[L] += 1 when
it appears only in y_true. This enables stable macro/weighted
averaging across batches even when some labels are absent from a given
sample, and lets result() return a {label: score} dict when
average=None.
If labels is None, a single global set-based TP/FP/FN is computed
over the pooled label values; in that mode average=None returns one
scalar (use labels=... for a per-label breakdown).
Example:
# for single label classification
class ListClassification(synalinks.DataModel):
label: Literal["label", "label_1", "label_2"]
# for multi label classification
class ListClassification(synalinks.DataModel):
labels: List[Literal["label", "label_1", "label_2"]]
# or use it with retrieval pipelines, in that case make sure to mask
# the correct fields.
class AnswerWithReferences(synalinks.DataModel):
sources: List[str]
answer: str
Compilation example:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
average
|
str
|
Type of averaging to be performed across per-field results
in the multi-field case.
Acceptable values are |
None
|
beta
|
float
|
Determines the weight of given to recall
in the harmonic mean between precision and recall. Defaults to |
1.0
|
labels
|
list
|
(Optional) Explicit list of label names to track.
When provided, accumulation is per-label across all batches and
|
None
|
name
|
str
|
(Optional) string name of the metric instance. |
'categorical_fbeta_score'
|
in_mask
|
list
|
(Optional) list of keys to keep to compute the metric. |
None
|
out_mask
|
list
|
(Optional) list of keys to remove to compute the metric. |
None
|
in_mask_pattern
|
str
|
(Optional) Regex pattern; fields whose names match
are kept (combined with |
None
|
out_mask_pattern
|
str
|
(Optional) Regex pattern; fields whose names match
are dropped (combined with |
None
|
Source code in synalinks/src/metrics/f_score_metrics.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 | |
get_config()
Return the serializable config of the metric.
Returns:
| Type | Description |
|---|---|
dict
|
The config dict. |